package com.playball.lottery.adapter;

import java.util.List;
import java.util.Map;

import com.playball.lottery.R;
import com.playball.lottery.frm.ads.AdvWebviewDetailActivity;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

/**
 * 
* @ClassName: AdvHomeAdapter 
* @Description: TODO(这里用一句话描述这个类的作用) 
* @author vanszhen 
* @date 2014年6月5日 下午3:53:44 
*
 */
public class AdvHomeAdapter extends BaseAdapter {
	
	
	
	/** 上下文 */
	private Context context;
	
	/** LayoutInflater */
	private LayoutInflater inflater = null;
	
	private List<Map<String, Object>> dataList;

	public AdvHomeAdapter(Context context) {
		super();
		this.context = context;
		inflater = LayoutInflater.from(context);
	}
	
	
	public   void setData(List<Map<String, Object>> dataList) {
		this.dataList = dataList ;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return dataList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return dataList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		if (convertView == null) {
			convertView=	inflater.inflate(R.layout.adv_home_item, null);
		}
		
		final String title = dataList.get(position).get("Title").toString();
		String time = dataList.get(position).get("DateTime").toString();
		final String tid = dataList.get(position).get("ID").toString();
		
		TextView txtTile = (TextView) convertView.findViewById(R.id.txt_item_title);
		txtTile.setText(title);
		TextView txtTime = (TextView) convertView.findViewById(R.id.txt_item_time);
		txtTime.setText(time);
		
		RelativeLayout layout = (RelativeLayout) convertView.findViewById(R.id.rl_web);
		layout.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(context, AdvWebviewDetailActivity.class);
				intent.putExtra("title", title);
				intent.putExtra("id", tid);
				//intent.putExtra("url", "http://www.baidu.com/index.php?tn=98012088_3_dg&ch=1");
				context.startActivity(intent);
			}
		});
		
		return convertView;
	}

}
